package PropertiesExample;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

public class PropertiesTest {
    public static void main(String[] args) {
        Properties properties = new Properties();

        try {
            // 读取Test1.properties文件
            InputStream input = new FileInputStream(".\\day6\\src\\PropertiesExample\\Test1.properties");
            properties.load(input);

            // 修改属性
            properties.setProperty("name", "tony");
            properties.setProperty("password", "111");

            // 显示修改后的属性
            properties.list(System.out);

            // 将修改后的属性写入Test2.properties文件
            OutputStream output = new FileOutputStream(".\\day6\\src\\PropertiesExample\\Test2.properties");
            properties.store(output, "Modified properties");

            // 关闭流
            input.close();
            output.close();

        } catch (IOException io) {
            io.printStackTrace();
        }
    }
}
